<include file="Public:header" />
<script type="text/javascript" src="__PUBLIC__/My97DatePicker/WdatePicker.js"></script>

<link rel="stylesheet" type="text/css" href="/Public/poshytip/tip-yellow/tip-yellow.css" />
<link rel="stylesheet" type="text/css" href="/Public/poshytip/tip-yellowsimple/tip-yellowsimple.css" />
<script type="text/javascript" src="/Public/poshytip/jquery.poshytip.min.js" ></script>

<style type="text/css">
  .table-list tr:hover {background:#a9d08e !important;}
</style>
<div class="subnav">
  <div class="explain-col" style="position: relative; background-color: #a9d08e;" id="add-list">
    <form name="addForm" id="addForm" method="POST" action="__CONTROLLER__/add">
      <table class="add-table">
        <tr>
          <td width="240">
            学员姓名：&nbsp;<input type="text" name="data[name]" id="name" size="20"  value="{$Think.get.name}" class="input-text" placeholder="请输入学员姓名" />
          </td>
          <td width="240">
            联系电话：&nbsp;<input type="text" name="data[phone]" id="phone" size="20"  value="{$Think.get.phone}" class="input-text" placeholder="请输入联系方式" /><span class="phone-prompt red"></span>
          </td>
          <td width="240">
            &nbsp;QQ号码：<input type="text" name="data[qq]" id="qq" size="20"  value="{$Think.get.qq}" class="input-text" placeholder="请输入QQ号码" />
          </td>
          <td>
            &nbsp;&nbsp;&nbsp;所在地：<input type="text" name="data[address]" id="address" size="20"  value="{$Think.get.address}" class="input-text" placeholder="请输入所在地" style="width: 200px;" />
            <span class="red">跟进记录：</span><input type="text" name="record_content" id="record_content" alue="{$Think.get.record_content}" class="input-text" placeholder="" style="width:480px;" />
          </td>
        </tr>
        <tr>
          <td>
            意向级别：
            <select name="data[level]" id="level">
              <option value="0">请选择级别</option>
              <volist name=":get_level_list()" id="vo">
                <option value="{$vo['id']}" {:selected($vo['id'],$info['level_text'])} >{$vo.name}</option>
              </volist>
            </select>
          </td>
          <td>
            详细级别：
            <select name="data[level_text]" id="level_text" >
              <option value="0">请选择级别</option>
              <volist name=":get_rank_list()" id="vo">
                <option value="{$vo['id']}" {:selected($vo['id'],$info['level_text'])} >{$vo.name}</option>
              </volist>
            </select>
          </td>
          <td>
            课程项目：
            <select name="data[course]" id="rourse">
              <option value="0">请选择所属分组</option>
              <volist name=":get_course_list()" id="vo">
                <option value="{$vo.id}"  >{$vo.name}</option>
              </volist>
            </select>
          </td>
          <td>
            课程详细：<input type="text" name="data[course_text]" id="course_text" alue="{$Think.get.course_text}" class="input-text" placeholder="" style="width:200px;" />
            下次跟进：<input type="text" name="talk_time2" id="talk_time2_add" size="30" placeholder="下次跟进时间"  value="" class="input-text Wdate" onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})" style="height:20px; width:120px; color:#999" />
            <label><input type="checkbox" id="talk_time2_no" value="1">&nbsp;无跟进时间</label>
          </td>
        </tr>

        <tr>
          <td>
            咨询方式：
            <select name="data[source]" id="source">
              <option value="0">请选择咨询方式</option>
              <volist name=":get_source_list()" id="vo">
                <option value="{$vo.id}"  >{$vo.name}</option>
              </volist>
            </select>
          </td>
          <td>
            &nbsp;&nbsp;&nbsp;合作方：
            <select name="data[partner]" id="partner">
              <option value="0">请选择合作伙伴</option>
              <volist name=":get_partner_list()" id="vo">
                <option value="{$vo.id}"  >{$vo.name}</option>
              </volist>
            </select>
          </td>
          <td colspan="2" class="red">
            <input type="submit" value=" 添加学员 " class="button" style="margin: 0 auto;" />
            <input type="button" value=" 导入学员 " class="button" style="margin: 0 auto; margin-left: 20px;" onclick="javascript:openWinBox('__CONTROLLER__/import_customer/','导入信息',500,160)" />
            <!-- <input type="button" value=" 隐藏添加 " class="button" id="hide-add-button"  style=" position: relative; top:50%; left:50%;" /> -->
          </td>

      </table>

    </form>
  </div>
  <div class="explain-col" style="position: relative; margin-top: 10px; background-color: #a9d08e">
    <form name="searchForm" id="searchForm" method="GET" action="">
      <input type="hidden" name="act" id="act" value="0">
      搜索：
      <input type="text" name="keyword" id="keyword" size="30" placeholder="学员名称"  value="{$Think.get.keyword}" class="input-text"  style="height:20px; width:80px; color:#999" />
      <input type="text" name="keyword2" id="keyword2" size="30" placeholder="手机号码"  value="{$Think.get.keyword2}" class="input-text"  style="height:20px; width:80px; color:#999" />
      <input type="text" name="keyword3" id="keyword3" size="30" placeholder="QQ"  value="{$Think.get.keyword3}" class="input-text"  style="height:20px; width:80px; color:#999" />
      <input type="text" name="keyword4" id="keyword4" size="30" placeholder="所在地"  value="{$Think.get.keyword4}" class="input-text"  style="height:20px; width:120px; color:#999" />

		  <eq name="Think.session.user_id" value="1">
	      <select name="user_id" id="user_id" onchange="searchForm.submit()">
	        <option value="0">所属顾问</option>
	        <volist name=":get_admin_list()" id="vo">
	          <option value="{$vo.id}" {:selected($vo['id'],$_GET['user_id'])}>{$vo.username}</option>
	        </volist>
	      </select>
	    </eq>

      <select name="source" id="source" onchange="searchForm.submit()">
        <option value="0">咨询方式</option>
        <volist name=":get_source_list()" id="vo">
          <option value="{$vo.id}" {:selected($vo['id'],$_GET['source'])}>{$vo.name}</option>
        </volist>
      </select>
      <select name="level" id="level" onchange="searchForm.submit()" style="width: 123px;">
        <option value="0">意向级别</option>
        <volist name=":get_level_list()" id="vo" onchange="searchForm.submit()">
          <option value="{$vo.id}" {:selected($vo['id'],$_GET['level'])}>{$vo.name}</option>
        </volist>
      </select>
  		<select name="rank" id="rank"  onchange="searchForm.submit()">
          <option value="0">详细详细级别</option>
          <volist name=":get_rank_list()" id="vo">
            <option value="{$vo['id']}" {:selected($vo['id'],$_GET['rank'])} >{$vo.name}</option>
          </volist>
        </select>

        <select name="course" id="rourse" onchange="searchForm.submit()">
          <option value="0">课程项目</option>
          <volist name=":get_course_list()" id="vo">
            <option value="{$vo.id}"  {:selected($vo['id'],$_GET['course'])}>{$vo.name}</option>
          </volist>
        </select>
        <input type="text" name="course_text" size="30" placeholder="课程详细"  value="{$Think.get.course_text}" class="input-text"  style="height:20px; width:120px; color:#999" />
        <input type="text" name="lurushijian" id="lurushijian" size="30" placeholder="录入时间"  value="{$Think.get.lurushijian}" class="input-text Wdate" onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})" style="height:20px; width:120px; color:#999" />
        <input type="text" name="shangci" id="shangci" size="30" placeholder="上次跟进时间"  value="{$Think.get.shangci}" class="input-text Wdate" onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})" style="height:20px; width:120px; color:#999" />
      <select name="talk_time2" id="talk_time2" onchange="searchForm.submit()" >
            <option value="0" selected="selected">下次跟进</option>
            <option value="1" <eq name="Think.get.talk_time2" value="1"> selected="selected"</eq> />今天</option>
            <option value="2" <eq name="Think.get.talk_time2" value="2"> selected="selected"</eq> />昨天</option>
            <option value="3" <eq name="Think.get.talk_time2" value="3"> selected="selected"</eq> />明天</option>
            <option value="4" <eq name="Think.get.talk_time2" value="4"> selected="selected"</eq> />本周</option>
            <option value="5" <eq name="Think.get.talk_time2" value="5"> selected="selected"</eq> />上周</option>
            <option value="6" <eq name="Think.get.talk_time2" value="6"> selected="selected"</eq> />下周</option>
            <option value="7" <eq name="Think.get.talk_time2" value="7"> selected="selected"</eq> />本月</option>
            <option value="8" <eq name="Think.get.talk_time2" value="8"> selected="selected"</eq> />上月</option>
            <option value="9" <eq name="Think.get.talk_time2" value="9"> selected="selected"</eq> />下月</option>
            <option value="10" <eq name="Think.get.talk_time2" value="10"> selected="selected"</eq> />本年</option>
            <!-- <option value="5" <eq name="Think.get.talk_time2" value="7"> selected="selected"</eq> />自定</option> -->
      </select>


      <!-- 签约时间：
      <input type="text" name="start_date" id="start_date" size="30" placeholder="开始时间"  value="{$Think.get.start_date}" class="input-text Wdate" onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})" readonly="readonly" style="height:20px; width:120px; color:#999" />-
      <input type="text" name="end_date" id="end_date" size="30" placeholder="结束时间"  value="{$Think.get.end_date}" class="input-text Wdate" onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})" readonly="readonly" style="height:20px; width:120px; color:#999" /> -->

      <input type="button" value=" 搜索 " class="button" id="searchButton" />
      <input type="button" value=" 全局搜索 " class="button" id="global-search" />
      <input type="button" value=" 默认排序 " class="button"  onclick="window.location.href='__URL__/index'" />
    </form>
    <div class="content-menu" style="position: absolute; right: 30px;top: 5px; display: none;"> <a href="javascript:openWinBox('__URL__/add','添加新客户',850);" class="add fb"><em>添加新客户</em></a> </div>
  </div>
</div>
<!--subnav-->
<div class="pad-lr-10">
  <form name="myform" id="myform" action="" method="post">
    <div class="table-list">
      <table width="100%" cellspacing="0">
        <thead>
          <tr>
            <th width="50" align="center">选择</th>
            <th align="center">录入时间</a></th>
            <th align="center">学员名称</th>
            <th align="center"><a href="__ACTION__/sort_level/{$sort_level|default=1}">意向级别<i class="th-sort"><img src="/Public/images/px.gif"></i></a></th>
            <th align="center"><a href="__ACTION__/sort_rank/{$sort_rank|default=1}">详细级别<i class="th-sort"><img src="/Public/images/px.gif"></i></a></th>
            <th align="center">所在地</th>
            <th align="center">课程项目</th>
            <th align="center">详细课程</th>
            <th align="center">联系电话</th>
            <th align="center">QQ</th>
            <!-- <th align="center">微信</th> -->
            <th align="center">上次跟进</th>
            <th align="center">剩余天数</th>
            <th align="center"><a href="__ACTION__/talk_time2_sort/{$talk_time2_sort|default=1}">下次跟进<i class="th-sort"><img src="/Public/images/px.gif"></i></a></th>
            <th align="center">电话内容</th>
            <th align="center">所属顾问</th>
            <th align="center">咨询方式</th>
            <th align="center">跟进次数</th>
            <eq name="act" value="0">
              <th align="center" width="180">操作</th>
            </eq>
          </tr>
        </thead>
        <tbody  id="list">
          <volist name="list" id="vo">
            <tr id="list-{$vo.id}" value="{$vo.id}" class="customer_list {$vo.class}" show="0">
              <td align="center">
                <eq name="act" value="0">
                  <input type="checkbox" name="idArr[]" value="{$vo.id}">
                <else />
                  {$i}
                </eq>
              </td>
              <td align="center">{$vo.create_time|mydate2}</td>
              <td align="center">{$vo.name}</td>
              <td align="center">{$vo.level|get_level_name}</td>
              <td align="center">{$vo.level_text}</td>
              <td align="center">{$vo.address}</td>
              <td align="center">{$vo.course|get_course_name}</td>
              <td align="center">{$vo.course_text}</td>
              <td align="center">{$vo.phone}</td>
              <td align="center">{$vo.qq}</td>
              <!-- <td align="center">{$vo.wechat}</td> -->
              <td align="center">{$vo.talk_time|mydate2}</td>
              <td align="center">{:time_diff($notTime,$vo['talk_time2'])}</td>
              <td align="center">{$vo.talk_time2|mydate2}</td>
              <td align="center" class="description" title="{$vo.content}" name="{$vo.id}">{$vo.content|cut=30}</td>
              <td align="center">{$vo.user_id|get_counselor_name}</td>
              <td align="center">{$vo.source|get_source_name}</td>
              <td align="center" class="talk_num">{$vo.talk_num}</td>
              <eq name="act" value="0">
                <td align="center">
                  <a href="javascript:openWinBox('__CONTROLLER__/add/id/{$vo.id}','客户信息',800,480)" >【修改】</a>
                  <a href="javascript:openWinBox('__CONTROLLER__/add_record/id/{$vo.id}','追加跟进内容')" >【添加跟进】</a>
                </td>
              </eq>
            </tr>
          </volist>
        </tbody>
      </table>
      <div class="btn">
        <div id="pages"><!-- 总计：{$count} -->{$page}</div>
        <eq name="act" value="0">
           <input name="submit" id="checkall" type="button" class="button" value="全选/反选">
           <input name="submit" type="button" class="button" value="放入公共池"  onclick="return owned();">
           <eq name="Think.session.user_id" value="1">
             <input name="submit" type="button" class="button" value="导出客户资料"  onclick="return exportExcel();">
             <input name="submit" type="button" class="button" value="删除所选"  onclick="return deleteConfirm();">
           </eq>
        </eq>
      </div>
    </div>
  </form>
</div>
</body>
</html>
<script type="text/javascript">
$(document).ready(function(e) {

  // $('.description').poshytip({className: 'tip-yellowsimple', showTimeout: 0.5,alignX: 'center',offsetY: 0,allowTipHover: true});

  //全反选
  $("#checkall").click(function(){
    $("input[name=idArr[]]").each(function(){
      if(this.checked == false)
        this.checked = true;
      else
          this.checked = false;
    });
  });

  $("#hide-add-button").click(function(){
    $("#add-list").hide();
    $(".content-menu").show();
  })


  //默认搜索
  $("#searchButton").click(function(){
    $("#act").val('0');
    $("#searchForm").submit();
  })

  //全局搜索
  $("#global-search").click(function(){
    $("#act").val('1');
    $("#searchForm").submit();
  })

  //异步获取通话记录
  $(".description").click(function(event) {

    var id = $(this).attr('name');
    var show = $("#list-"+id).attr('show');
    var num = $(this).siblings('.talk_num').html();

    if(num<1) return false; //当电话记录为空的时候返回false

    if(show==0){
      set_record_list(id);
      $("#list-"+id).attr('show',1);
    }else if(show==1){
      $(".record-"+id).hide();
      $("#list-"+id).attr('show',2);
    }else{
      $(".record-"+id).show();
      $("#list-"+id).attr('show',1);
    }

  });

  //异步判断电话号码是否存在
  $("#phone").change(function(){
    var phone = $(this).val();
    if(phone=='') {
      $(this).next().html('');
      return false;
    }

    $.get("__CONTROLLER__/check_phone", { phone: phone },
    function(data){
      if(data.status==1){
        $(".phone-prompt").html(data.info);
      }else{
        $(".phone-prompt").html('');
      }
    });
  })

});

//导出
function exportExcel(){
  $("#searchForm").attr('action','__CONTROLLER__/export_excel');
  $("#searchForm").submit();
  return false;
}

function set_record_list(id){
  $.ajax({
      type:'GET',
      url:"__CONTROLLER__/get_record_list",
      dataType:'text',
      data:encodeURI('id='+id),
      beforeSend:function(){
        $('#list-'+id).after('<tr class="jiazai"><td align="center" colspan="10" style="color:#F00" >正在加载。。。</td></tr>');
        $('.call-records').hide();
        $('.current-bg').removeClass('current-bg');
      },
      success:function(data){
        var data = eval('('+data+')');
        $('#list-'+id).after(data.data);
          $('#list-'+id).addClass('current-bg');
        $('#content-'+id).addClass('current-bg');
      },
      complete: function(XMLHttpRequest, textStatus){
        $('.jiazai').remove();
      },
      error: function(){}
    });
    return true;
}

function deleteConfirm() {
    art.dialog({
        content: '确定删除所选数据吗？',
        ok: function() {
            del();
            return true;
        },
        cancelVal: '取消',
        cancel: true
    });
}

function del() {
    var idArr = Array();
    var i = 0;
    var id;
    $("input[name='idArr[]']").each(function() {
        if (this.checked == true) {
            idArr[i] = $(this).val();
            i++;
        }
    });
    jQuery.get('__CONTROLLER__/del', encodeURI('id=' + idArr), success, 'json');

    function success(data) {
        if (data.status == 1) {
            window.top.art.dialog({
                id: 'TNCICC',
                content: data.info,
                time: 1,
                icon: 'succeed'
            });
            setTimeout(function() {
              window.location.reload();
            }, 1000);
        } else {
            window.top.art.dialog({
                id: 'TNCICC',
                content: data.info,
                time: 1,
                icon: 'warning'
            });
        }

    }
}

</script>


<script type="text/javascript">
$(document).ready(function(e) {

  $('#addForm').ajaxForm({
      beforeSubmit:  checkForm,
      success:       complete,
      dataType: 'json'
  });

  function checkForm(){
    var name = $("#name").val();
    var role_id = $("#role_id").val();
    var talk_time2 = $("#talk_time2_add").val();
    var talk_time2_no = $("#talk_time2_no").val();




    if( name=='' ){
      art.dialog({id:'TNCICC',content: '请输入学员姓名',time: 2,icon:'warning'});
      $('#name').focus();
      return false;
    }

    if(role_id==0){
      art.dialog({id:'TNCICC',content: '请选择所属顾问',time: 2,icon:'warning'});
      return false;
    }


    if (!$('#talk_time2_no').attr('checked')) {
      if(talk_time2==0||talk_time2==''){
        art.dialog({id:'TNCICC',content: '下次跟进时间不能为空！',time: 2,icon:'warning'});
        return false;
      }
    }

    return true;
  }

  var origin = $.artDialog.open.origin;
  function complete(data){
    if(data.status==1){
      art.dialog({id:'TNCICC',content: data.info,time: 1,icon:'succeed'});
      setTimeout(function(){origin.location.reload();closeWin()},1500);
    }else{
      art.dialog({id:'TNCICC',content: data.info,time: 1,icon:'warning'});
    }

  }

});




function owned() {
    art.dialog({
        content: '确定将所选择的学员放入公共池吗？',
        ok: function() {
            to_owned();
            return true;
        },
        cancelVal: '取消',
        cancel: true
    });
}

function to_owned() {
    var idArr = Array();
    var i = 0;
    var id;
    $("input[name='idArr[]']").each(function() {
        if (this.checked == true) {
            idArr[i] = $(this).val();
            i++;
        }
    });
    jQuery.get('__CONTROLLER__/owned/status/2', encodeURI('id=' + idArr), success, 'json');

    function success(data) {
        if (data.status == 1) {
            window.top.art.dialog({
                id: 'TNCICC',
                content: data.info,
                time: 1,
                icon: 'succeed'
            });
            setTimeout(function() {
              window.location.reload();
            }, 1000);
        } else {
            window.top.art.dialog({
                id: 'TNCICC',
                content: data.info,
                time: 1,
                icon: 'warning'
            });
        }

    }
}

</script>